import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
//定义单张牌，并获得相应的方法
class Card{
    private String suit;
    private int rang;

    public Card(String suit, int rang) {
        this.suit = suit;
        this.rang = rang;
    }

    @Override
    public String toString() {
        return "[" + suit + "  "  + rang +"]";
    }

    public String getSuit() {
        return suit;
    }

    public void setSuit(String suit) {
        this.suit = suit;
    }

    public int getRang() {
        return rang;
    }

    public void setRang(int rang) {
        this.rang = rang;
    }
}
//玩牌
public class TestDemo {
    //定义一副牌的花色
    private static final String[] suit={"♥","♠","♣","♦"};
//制作一副牌
    public static  ArrayList<Card> buyCard(){
        ArrayList<Card> list=new ArrayList<Card>();
        for (int i = 0; i < suit.length; i++) {
            for (int j = 1; j <= 13; j++) {
                Card card=new Card(suit[i],j);
                list.add(card);
            }
        }
        return list;
    }
    //调换洗牌
    public static void swap(ArrayList<Card> cards,int i,int rand){
           Card tmp=cards.get(i);
           cards.set(i,cards.get(rand));
           cards.set(rand,tmp);
    }
    //洗牌，生产随机下标，与现阶段循环进行调换
    public static void shuffle(ArrayList<Card> cards){
        int size= cards.size();
        for (int i = size-1; i > 0; i--) {
            Random random=new Random();
           int rand =random.nextInt(i);
           swap(cards,i,rand);
        }
    }
    public static void main2(String[] args) {
          ArrayList<Card> arrayList=buyCard();
        System.out.println("买牌"+arrayList);
        shuffle(arrayList);
        System.out.println("洗牌"+arrayList);
        //定一个发牌手，发牌手给3个选手发牌
        List<ArrayList<Card>> hand=new ArrayList<>();
        //三个选手每人拿牌
        ArrayList<Card> hand1=new ArrayList<>();
        ArrayList<Card> hand2=new ArrayList<>();
        ArrayList<Card> hand3=new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        for (int i = 0; i < 5; i++) {//发牌五轮
            for (int j = 0; j < 3; j++) {//发牌三人，每次发一张，相当于每次发三张
                Card card=arrayList.remove(0);//发完的牌移除，不能使其重复
                hand.get(j).add(card);
            }
        }
        System.out.println("第一个人的牌"+hand1);
        System.out.println("第二个人的牌"+hand2);
        System.out.println("第三个人的牌"+hand3);
        System.out.println("剩余的牌"+arrayList);
    }


    public static void main1(String[] args) {
        Card card=new Card("♥",3);
        System.out.println(card);

    }

    public static void main3(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int num=scanner.nextInt();
        List<ArrayList<Integer>> ret=new ArrayList<>();
        ArrayList<Integer> list1=new ArrayList<>();
        list1.add(1);
        ret.add(list1);
        for (int i = 1; i < num; i++) {
            ArrayList<Integer> list=new ArrayList<>();
            list.add(1);
            ArrayList<Integer> preRow=ret.get(i-1);
            for (int j = 1; j < i; j++) {
                int num1=preRow.get(j)+preRow.get(j-1);
                list.add(num1);
            }
            list.add(1);
            ret.add(list);
        }
        System.out.println(ret);
    }
//杨辉三角
    public static void main4(String[] args) {
        int num=9;
        //面向对象，首先需要创建一个大数组，大数组中存储单个行数组
        List<ArrayList<Integer>> list=new ArrayList<>();
        //创建单行数组对象，存放元素
        ArrayList<Integer> arrayList1=new ArrayList<>();
        //每一行的第一个元素为1
        arrayList1.add(1);
        //大数组的第一行对象只有一个1
        list.add(arrayList1);
        //生产总的行数，需要的行数
        for (int i = 1; i < num; i++) {
            //每一行为一个小对象，新建对象
            ArrayList<Integer> arrayList=new ArrayList<>();
            //每一行的对象首字符为1
            arrayList.add(1);
            //根据规律，先储存当前行的上一行
            ArrayList<Integer> preRow=list.get(i-1);

            for (int j = 1; j < i; j++) {
                //生产当前行的每一个数字
                int num1=preRow.get(j)+preRow.get(j-1);
                //添加数字
                arrayList.add(num1);
            }
            //当前行对象的最后添加1
            arrayList.add(1);
            //将当前行对象添加到大的对象中列表中
            list.add(arrayList);
        }
        System.out.println(list);
    }

    public static void main(String[] args) {
        int num=9;
        List< ArrayList<Integer>> list=new ArrayList<>();
        ArrayList<Integer> arrayList1=new ArrayList<>();
        arrayList1.add(1);
        list.add(arrayList1);
        for (int i = 1; i < num; i++) {
            ArrayList<Integer> arrayList=new ArrayList<>();
            arrayList.add(1);
            ArrayList<Integer> preRow=list.get(i-1);
            for (int j = 1; j < i; j++) {
                int num1=preRow.get(j)+preRow.get(j-1);
                arrayList.add(num1);
            }
            arrayList.add(1);
            list.add(arrayList);
        }
        System.out.println(list);

    }
}
